package entity.connector;

import entity.bean.Show;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 *
 * @author Lusinda
 */
public class ShowUploader {
    public static boolean addShow(Show show){
        try {
            Connection con = ConnectionProvider.getCon();
            PreparedStatement ps = con.prepareStatement("INSERT INTO movie_show VALUES (?,?,?,?)");
            ps.setInt(1, show.getMovieID());
            ps.setString(2, TimeConvertor.calendarToString(show.getTime()));
            ps.setInt(3, show.getHouseID());
            ps.setInt(4, show.getPrice());
            int status = ps.executeUpdate();
            ps.close();
            if (status == 0){
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
    public static boolean editShow(Show show){
        try {
            Connection con = ConnectionProvider.getCon();
            PreparedStatement ps = con.prepareStatement(
                    "UPDATE movie_show SET movie_time = ?, price = ? WHERE movie_id = ?");
            ps.setString(1, TimeConvertor.calendarToString(show.getTime()));
            ps.setInt(2, show.getPrice());
            ps.setInt(3, show.getMovieID());
            int status = ps.executeUpdate();
            ps.close();
            if (status == 0){
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
    public static void removeShow(Show show){
        try {
            Connection con = ConnectionProvider.getCon();
            PreparedStatement ps = con.prepareStatement(
                    "DELETE FROM movie_show WHERE movie_id = ?");
            ps.setInt(1, show.getMovieID());
            int status = ps.executeUpdate();
            ps.close();
        } catch (Exception e) {
        }
    }
}